﻿using System;
using System.Collections.Generic;
using Model;
using EFEntity;
using System.Threading.Tasks;
using System.Linq;
using Iservices;

namespace Services
{
    public class salary_grant_detailsService: Isalary_grant_detailsService
    {
        private readonly MyDbContext myDbContext;

        public salary_grant_detailsService(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }

        public Task<int> Add(salary_grant_details t)
        {
            throw new NotImplementedException();
        }

        public Task<int> Delete(int id)
        {
            throw new NotImplementedException();
        }

        public Task<List<salary_grant_details>> FenYe(FenYe fy)
        {
            throw new NotImplementedException();
        }

        public async Task<List<salary_grant_details>> SelectAll()
        {
            List<Esalary_grant_details> list = new List<Esalary_grant_details>();
            await Task.Run(() =>
            {
                list = myDbContext.salary_grant_details.ToList();
            });

            List<salary_grant_details> list2 = new List<salary_grant_details>();
            foreach (Esalary_grant_details t in list)
            {
                salary_grant_details ck = new salary_grant_details()
                {
                    grd_id=t.grd_id,
                    salary_grant_id=t.salary_grant_id,
                    human_id=t.human_id,
                    human_name=t.human_name,
                    bouns_sum=t.bouns_sum,
                    deduct_sum=t.deduct_sum,
                    sale_sum=t.sale_sum,
                    salary_paid_sum=t.salary_paid_sum,
                    salary_standard_sum=t.salary_paid_sum

                };
                list2.Add(ck);
            }
            return list2;
        }

        public Task<salary_grant_details> SelectID(int id)
        {
            throw new NotImplementedException();
        }

        public async Task<int> Update(salary_grant_details t)
        {
            Esalary_grant_details test = new Esalary_grant_details()
            {
                grd_id = t.grd_id,
                salary_grant_id = t.salary_grant_id,
                human_id = t.human_id,
                human_name = t.human_name,
                bouns_sum = t.bouns_sum,
                deduct_sum = t.deduct_sum,
                sale_sum = t.sale_sum,
                salary_paid_sum = t.salary_paid_sum,
                salary_standard_sum = t.salary_standard_sum

            };
            myDbContext.salary_grant_details.Attach(test);
            myDbContext.Entry(test).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return await myDbContext.SaveChangesAsync();
        }
    }
}
